package com.gexin.controller.xapp.acitivity;

import com.gexin.common.model.ApiResponse;
import com.gexin.core.interceptor.XAppSafeInterceptor;
import com.gexin.core.web.AppController;
import com.gexin.model.activity.*;
import com.gexin.model.weixin.WeixinUser;
import com.gexin.service.memberAcitivty.CashCoupService;
import com.gexin.service.memberAcitivty.MemberInfoService;
import com.jfinal.aop.Before;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.tx.Tx;
import java.util.List;
import java.util.Map;

@Before(XAppSafeInterceptor.class)//统一错误拦截
@ControllerBind(controllerKey = "/xapp/CashCoupController")
public class CashCoupController extends AppController {

    private static final CashCoupService cashCoupService = new CashCoupService();

    private MemberInfoService memberInfoService = new MemberInfoService();


    /**
     *收益和支出(日志)
     */
    public void getInteralDetails() {
        int status = getParaToInt("status");
        String authUser = getAuthUser().getId()+"";
        List<MemberIntegralLog> memberIntegralLogPage = cashCoupService.integralOrder(authUser, status);
        renderJson(new ApiResponse(true,"返回成功",memberIntegralLogPage));
        return;
    }


    /**
     *收益和支出(日志)
     */
    public void getInteralDetailsVistor() {
        int status = getParaToInt("status");
        String authUser = getAuthUser().getId()+"";
        List memberIntegralLogPage = cashCoupService.vistorIntegralOrder(authUser, status);
        renderJson(new ApiResponse(true,"返回成功",memberIntegralLogPage));
        return;
    }

    /**
     * 兑货券兑换商品,佣金的日志(累计记录)
     * @param
     */
    public void getCashCouponLog(){
        String id = getAuthUser().getId()+"";
        List<CashCouponLog> commision = cashCoupService.getCashCouponLog(id);
        ApiResponse apiResponse = new ApiResponse(true,"返回成功",commision);
        renderJson(apiResponse);
        return;
    }



    /**
     */
    @Before(Tx.class)
    public void integralExchangeProduct()throws Exception {
        int productId = getParaToInt("productId");
        int address = getParaToInt("addressId");
        int num = getParaToInt("num");
        String phone = getPara("phone");
        WeixinUser authUser = getAuthUser();
         int isXapp = isXapp() == true ? 1 : 2;
        ApiResponse apiResponse = cashCoupService.integralExchangeProduct(authUser.getId() + "",
                productId,num,phone,address,isXapp);
        renderJson(apiResponse);
        return;
    }


    /**
     * 积分兑换首页
     */
    public void getIntegralRegionProductList(){
        Map integralRegionAllProduct = cashCoupService.getIntegralRegionAllProduct();
        renderJson(integralRegionAllProduct);
    }



    /**
     * 获得所有兑货券详情
     */
    public void speedIntegralList(){
        String id = getAuthUserId()+"";
        List<MemberOrder> memberOrderIntegralList = cashCoupService.getCashCouponLogList(id);
        ApiResponse apiResponse = new ApiResponse(true,"返回成功",memberOrderIntegralList);
        renderJson(apiResponse);
        return;
    }


    /**
     * 获取兑货券信息
     */
    public void speedIntegral(){
        WeixinUser authUser = getAuthUser();
        renderJson(memberInfoService.getSpeedIntegral(authUser));
        return;
    }





}
